/**
* Copyright (c) By zengqh.
*
* This program is just for fun or demo, in the hope that it  
* will be useful, you can redistribute it and/or modify freely.
*
* Time: 2013/03/03
* File: Texture.h
* Blog: http://www.cnblogs.com/zengqh/
**/

#pragma once

#include "RenderObject.h"

namespace HY
{
class Texture : public RenderObject
{
public:
	virtual ~Texture()
	{

	}

	uint32 getFormat() const
	{
		return format_;
	}

	bool isCompressedFormat() const
	{
		return isCompressedFormat(format_);
	}

	bool isCompressedFormat(uint32 format) const
	{
		switch (format)
		{
		case PixelFormat::DXT1:			
		case PixelFormat::DXT3:			
		case PixelFormat::DXT5:			
			return true;
		default:			
			return false;
		}
	}

	bool isDepthFormat() const
	{
		return isDepthFormat(format_);
	}

	bool isDepthFormat(uint32 format) const
	{
		switch (format) 
		{
		case PixelFormat::D16:
		case PixelFormat::D24:
		case PixelFormat::D32:
			return true;
		default:
			return false;
		}
	}

	
	bool isFloatPointFormat() const
	{
		return isFloatPointFormat(format_);
	}

	bool isFloatPointFormat(uint32 format) const
	{
		switch (format) 
		{
		case PixelFormat::F16_1:
		case PixelFormat::F16_2:
		case PixelFormat::F16_4:
		case PixelFormat::F32_1:
		case PixelFormat::F32_4:
			return true;
		default:			
			return false;
		}
	}

	uint32 getBytesPerPixel(uint32 format)
	{
		switch (format) 
		{
		case PixelFormat::U1:			return 1;
		case PixelFormat::U3:			return 3; 
		case PixelFormat::U4:			return 4;
		case PixelFormat::U16_1:		return 2;
		case PixelFormat::U16_2:		return 4;
		case PixelFormat::U16_4:		return 8;
		case PixelFormat::D16:			return 2;
		case PixelFormat::D24:			return 3;
		case PixelFormat::D32:			return 4;
		case PixelFormat::DXT1:		
		case PixelFormat::DXT3:
		case PixelFormat::DXT5:			return 0;
		case PixelFormat::F16_1:		return 2;
		case PixelFormat::F16_2:		return 4;
		case PixelFormat::F16_4:		return 8;
		case PixelFormat::F32_1:		return 4;
		case PixelFormat::F32_2:		return 8;
		case PixelFormat::F32_4:		return 16;
		default:		return 0;
		}
	}

	virtual void setSamplerAddressMode(uint32 sampler, uint32 mode)
	{
		if (sampler >= Sampler::Number)
		{
			return;
		}

		sampler_mode_[sampler] = mode;
	}

	virtual void getSamplerAddressMode(uint32 sampler, uint32& mode)
	{
		if (sampler >= Sampler::Number)
		{
			return;
		}

		mode = sampler_mode_[sampler];
	}
	
protected:
	Texture(uint32 type)
		: RenderObject(type)
	{
		sampler_mode_[Sampler::Address] = SamplerAddressMode::ADDRESS_WRAP;
		sampler_mode_[Sampler::Filter] = SamplerFilterMode::FILTER_BILINEAR;
	}

protected:
	uint32			format_;
	uint32			sampler_mode_[SamplerFilterMode::Number];
};
}